Net Stop MSExchangeTransport
Net Stop MSExchangeRPC
Net Stop W3SVC
Net Start W3SVC

$EXDIR="D:\ProcessAttachmentAndSecureText"

Write-Output "Creating directories..."
New-Item -Type Directory -path $EXDIR -ErrorAction SilentlyContinue
New-Item -Type Directory -path $EXDIR\Log -ErrorAction SilentlyContinue

Write-Output "Copying files..."
Copy-Item bin\debug\ProcessAttachmentAndSecureText.dll $EXDIR\ -force
Copy-Item bin\debug\ProcessAttachmentAndSecureText.pdb $EXDIR\ -force
Copy-Item ProcessAttachmentAndSecureText.dll.config $EXDIR\ -force

Write-Output "Registering agent..."
Install-TransportAgent -Name "Process Attachment And Secure Text" -AssemblyPath $EXDIR\ProcessAttachmentAndSecureText.dll -TransportAgentFactory "ProcessAttachmentAndSecureText.CustomAgents.CustomAgentFactory"

Write-Output "Enabling agent"
Enable-TransportAgent -Identity "Process Attachment And Secure Text"
Get-TransportAgent -Identity "Process Attachment And Secure Text"

Net Start MSExchangeRPC
Net Start MSExchangeTransport

Write-Output "Installation complete. Please exit the Exchange Management Shell."


